home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / PasswordedDownload / PasswordedDownload.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  6.4 KB  |  237 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.FlowLayout;
  7. import java.awt.GridLayout;
  8. import java.awt.Label;
  9. import java.awt.LayoutManager;
  10. import java.awt.Panel;
  11. import java.awt.TextField;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.net.MalformedURLException;
  15. import java.net.URL;
  16. import java.net.URLEncoder;
  17. import java.util.EventObject;
  18.  
  19. public class PasswordedDownload extends Applet implements ActionListener {
  20.    public String url;
  21.    public String title = "Enter the password";
  22.    // $FF: renamed from: wi int
  23.    private int field_0;
  24.    // $FF: renamed from: he int
  25.    private int field_1;
  26.    private int frameWidth = 250;
  27.    private int frameHeight = 150;
  28.    // $FF: renamed from: t2 java.awt.TextField
  29.    public TextField field_2;
  30.    private String passwordText = "Password";
  31.    private LoginFrame frame;
  32.    private int wib;
  33.    private int heb;
  34.    private String text;
  35.  
  36.    public String getAppletInfo() {
  37.       return "Name: PasswordedDownload\r\nAuthor: Taiji Software\r\n";
  38.    }
  39.  
  40.    public void register() {
  41.       try {
  42.          URL u = new URL("http://www.taijisoftware.com");
  43.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  44.       } catch (Exception e) {
  45.          System.out.println(e);
  46.       }
  47.    }
  48.  
  49.    public void init() {
  50.       String codeBase = null;
  51.  
  52.       try {
  53.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  54.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  55.          codeBase = codeBase.toUpperCase();
  56.       } catch (Exception var9) {
  57.       }
  58.  
  59.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  60.          String regCode = ((Applet)this).getParameter("registration_code");
  61.          if (regCode == null) {
  62.             regCode = ((Applet)this).getParameter("reg_domain");
  63.             if (regCode == null) {
  64.                this.register();
  65.             } else {
  66.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  67.                   codeBase = "WWW." + codeBase;
  68.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  69.                   codeBase = codeBase.substring(4);
  70.                }
  71.  
  72.                char[] chars = new char[codeBase.length()];
  73.                codeBase.getChars(0, codeBase.length(), chars, 0);
  74.                String key = new String("haricot");
  75.                char[] chars2 = new char[key.length()];
  76.                key.getChars(0, key.length(), chars2, 0);
  77.  
  78.                for(int i = 0; i < codeBase.length(); ++i) {
  79.                   int j;
  80.                   if (i >= key.length()) {
  81.                      j = i - key.length() * (i / key.length());
  82.                   } else {
  83.                      j = i;
  84.                   }
  85.  
  86.                   chars[i] += chars2[j];
  87.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  88.                }
  89.  
  90.                String res = new String(chars);
  91.                if (!res.equalsIgnoreCase(regCode)) {
  92.                   this.register();
  93.                }
  94.             }
  95.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  96.             this.register();
  97.          }
  98.       }
  99.  
  100.       this.getParameters();
  101.       this.putComponents();
  102.    }
  103.  
  104.    public void stop() {
  105.       this.frame.dispose();
  106.    }
  107.  
  108.    public void getParameters() {
  109.       this.field_0 = ((Component)this).getSize().width;
  110.       this.field_1 = ((Component)this).getSize().height;
  111.       String s = ((Applet)this).getParameter("button_width");
  112.       if (s != null) {
  113.          this.wib = Integer.parseInt(s);
  114.       } else {
  115.          this.wib = this.field_0;
  116.       }
  117.  
  118.       s = ((Applet)this).getParameter("button_height");
  119.       if (s != null) {
  120.          this.heb = Integer.parseInt(s);
  121.       } else {
  122.          this.heb = this.field_1;
  123.       }
  124.  
  125.       this.text = ((Applet)this).getParameter("button_text");
  126.       s = ((Applet)this).getParameter("title");
  127.       if (s != null) {
  128.          this.title = s;
  129.       }
  130.  
  131.       s = ((Applet)this).getParameter("frame_width");
  132.       if (s != null) {
  133.          this.frameWidth = Integer.parseInt(s);
  134.       }
  135.  
  136.       s = ((Applet)this).getParameter("frame_height");
  137.       if (s != null) {
  138.          this.frameHeight = Integer.parseInt(s);
  139.       }
  140.  
  141.       s = ((Applet)this).getParameter("password_text");
  142.       if (s != null) {
  143.          this.passwordText = s;
  144.       }
  145.  
  146.       if (((Applet)this).getParameter("background_color") != null) {
  147.          ((Component)this).setBackground(this.getColor("background_color"));
  148.       }
  149.  
  150.    }
  151.  
  152.    public Color getColor(String param) {
  153.       String s = ((Applet)this).getParameter(param);
  154.       if (s != null) {
  155.          if (s.substring(0, 1).equals("#")) {
  156.             s = s.substring(1);
  157.             int i = Integer.parseInt(s, 16);
  158.             return new Color(i);
  159.          } else {
  160.             return null;
  161.          }
  162.       } else {
  163.          return null;
  164.       }
  165.    }
  166.  
  167.    public void putComponents() {
  168.       Button b = new Button(this.text);
  169.       ((Container)this).setLayout((LayoutManager)null);
  170.       ((Container)this).add(b);
  171.       ((Component)b).setSize(this.wib, this.heb);
  172.       ((Component)b).setLocation((this.field_0 - this.wib) / 2, (this.field_1 - this.heb) / 2);
  173.       ((Component)b).setBackground(this.getColor("button_color"));
  174.       b.addActionListener(this);
  175.    }
  176.  
  177.    public void putComponents2() {
  178.       this.frame = new LoginFrame(this.title, this);
  179.       this.frame.setBounds(200, 200, this.frameWidth, this.frameHeight);
  180.       this.frame.setLayout(new FlowLayout());
  181.       Panel p1 = new Panel();
  182.       ((Container)p1).setLayout(new GridLayout(1, 2));
  183.       ((Container)p1).add(new Label(this.passwordText));
  184.       this.field_2 = new TextField(10);
  185.       this.field_2.setEchoChar('*');
  186.       ((Container)p1).add(this.field_2);
  187.       Panel p2 = new Panel();
  188.       ((Container)p2).setLayout(new FlowLayout());
  189.       Button b1 = new Button("Ok");
  190.       b1.addActionListener(this.frame);
  191.       ((Container)p2).add(b1);
  192.       Button b2 = new Button("Cancel");
  193.       b2.addActionListener(this.frame);
  194.       ((Container)p2).add(b2);
  195.       this.frame.add(p1);
  196.       this.frame.add(p2);
  197.       if (((Applet)this).getParameter("frame_background_color") != null) {
  198.          this.frame.setBackground(this.getColor("frame_background_color"));
  199.       } else {
  200.          this.frame.setBackground(Color.gray);
  201.       }
  202.  
  203.       this.frame.setVisible(true);
  204.    }
  205.  
  206.    public void actionPerformed(ActionEvent evt) {
  207.       Button var10000 = (Button)((EventObject)evt).getSource();
  208.       this.putComponents2();
  209.    }
  210.  
  211.    public URL giveURL(String url) {
  212.       try {
  213.          if (url.toUpperCase().startsWith("HTTP")) {
  214.             return new URL(url);
  215.          } else if (url.toUpperCase().startsWith("FTP")) {
  216.             int p = url.indexOf(":");
  217.             int p2 = url.indexOf(":", p + 1);
  218.             if (p2 != -1) {
  219.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  220.             }
  221.  
  222.             p = url.indexOf("%40");
  223.             if (p != -1) {
  224.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  225.             }
  226.  
  227.             return new URL(url);
  228.          } else {
  229.             return new URL(((Applet)this).getCodeBase(), url);
  230.          }
  231.       } catch (MalformedURLException e) {
  232.          System.out.println(e);
  233.          return null;
  234.       }
  235.    }
  236. }
  237.